<template>
  <div class="common-parameter" ref="pageView" v-loading="loading">
    <div class="select">
      <el-row
        class="order-title"
        type="flex"
        justify="space-between"
        align="middle"
      >
        <el-form
          ref="search"
          class="order-search"
          :inline="true"
          :model="search"
          :show-message="false"
        >
          <el-form-item>
            <el-select
              v-model="search.cj"
              placeholder="选择车间"
              size="small"
              clearable
            >
              <template #prefix>车间： </template>
              <el-option
                v-for="item in cjOption"
                :key="item.id"
                :label="item['key_value']"
                :value="item['key_value']"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="品种类型">
             <el-input
                v-model="search.pzlx"
                type="text"
                size="small"
                placeholder="请输入"
              ></el-input>
          </el-form-item>
          <el-form-item label="品种">
             <el-input
                v-model="search.pz"
                type="text"
                size="small"
                placeholder="请输入"
              ></el-input>
          </el-form-item>
        </el-form>
        <div>
          <el-button size="small" type="primary" @click="onSearch">搜索</el-button>
          <el-button size="small">导出</el-button>
        </div>
      </el-row>
    </div>
    <div style="margin-top:15px">
      <el-row type="flex" justify="space-between" align="center">
        <div class="common-title">品种公定参数列表</div>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click="addCommonParameter"
          >新建公定参数</el-button
        >
      </el-row>
      <div class="common-main">
        <div class="common-table" ref="table">
          <el-table
            border
            :data="tableData"
            style="width: 100%"
            :max-height="tableHeight"
          >
            <el-table-column
              prop="cj"
              label="车间"
              width="80"
              align="center"
              fixed="left"
            >
            </el-table-column>
            <el-table-column
              prop="pzlx"
              label="品种类型"
              width="100"
              align="center"
              fixed="left"
            >
            </el-table-column>
            <el-table-column
              prop="pz"
              label="品种"
              width="140"
              align="center"
              fixed="left"
            >
            </el-table-column>
            <el-table-column
              prop="zs"
              label="支数"
             width="60"
              align="center"
              fixed="left"
            >
            </el-table-column>
            <el-table-column
              prop="dcpzxs"
              label="挡车品种系数"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lspzxs"
              label="落纱品种系数"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="dcdjxs"
              label="挡车单价系数"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lsdjxs"
              label="落纱单价系数"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="dcbzkts"
              label="挡车标准看台"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lsbzkts"
              label="落纱标准看台"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="pzgdl"
              label="品种公定量(G/100M)"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="cdtb12"
              label="长度/台班(百米)/12小时"
             width="100"
              align="center"
            >
             </el-table-column>

            <el-table-column
              prop="decl"
              label="定额产量516/日"
             width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="sjlscs"
              label="实际落纱次数/天"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="dcdj"
              label="挡车单价(元/百米)"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="dcjsgz8"
              label="挡车计时工资(8小时)"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="lsdj"
              label="落纱单价(元/百米)"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lsjsgz8"
              label="落纱计时工资(8小时)"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="lsqjdj"
              label="落纱清洁单价(元/台)"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lsdjCs"
              label="落纱单价(次)"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="hsdj"
              label="换纱单价(锭)"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="bgdj"
              label="摆管单价(元/台)"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="txsdj"
              label="推细纱单价(元/台)"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="dcsfjj"
              label="挡车是否计件"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="lssfjj"
              label="落纱是否计件"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="dcdjYfa"
              label="挡车单价(元/百米)原方案"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="lsdjYfa"
              label="落纱单价(元/百米)原方案"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="lsqjdjYfa"
              label="落纱清洁单价(元/台)原方案"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="lsdjYfa"
              label="落纱单价(次)原方案"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="hsdjYfa"
              label="换纱单价(锭)原方案"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="bgdjYfa"
              label="摆管单价(元/台)原方案"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="txsdjYfa"
              label="推细纱单价(元/台)原方案"
              width="100"
              align="center"
            >
             </el-table-column>
            <el-table-column
              prop="cp"
              label="车号"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="ds"
              label="锭数"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="jtxs"
              label="机台系数"
              width="100"
              align="center"
            >
            </el-table-column>
            
            <el-table-column
                prop="dcg"
                label="操作"
                width="60"
                align="center"
                fixed="right"
              >
                <div class="table-btn" slot-scope="{ row }">
                  <el-button 
                  type="text"
                  icon="el-icon-edit-outline"
                  size="small"
                  style="padding:0"
                  @click.stop="onEdit(row)">编辑</el-button>
                  <!-- <el-divider direction="vertical"></el-divider>
                  <el-button  
                  type="text"
                  icon="el-icon-delete"
                  class="danger"
                  style="padding:0"
                  size="small"
                  @click.stop="onDel(row)">删除</el-button> -->
                </div>
              </el-table-column>
          </el-table>
        </div>
        <div class="pagination">
          <el-pagination
            background
            layout="sizes, prev, pager,next "
            :page-size="search.size"
            :current-page.sync="search.page"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <AddCommonParameter ref="AddCommonParameter" @update="getTableData"></AddCommonParameter>
  </div>
</template>
<script>
import { queryVarietyParameters,deleteVarietyParameters } from '@/api/salaryReport'
import AddCommonParameter from '../components/AddCommonParameter.vue';

export default {
  components: { AddCommonParameter },
  data() {
    return {
      loading:true,
      tableHeight: 500,
      // 时间选择器
      search: {
        // cj: '',
        // pz: '',
        page: 1,
        size: 10
      },
      tableData: [],
      total: 10,
    };
  },
  computed: {
    // 车间
    cjOption() {
      return this.$store.getters.cjOption;
    },
    // 品种
    pzOption() {
      return this.$store.getters.pzOption;
    },
  },
  created() {
    this.getTableData();
  },
  mounted() {
    // 获取table 高度
    this.$nextTick(() => {
      this.getHeight();
    });
  },
  methods: {
    onEdit(data) {
      this.$refs['AddCommonParameter'].edit(data);
    },
    onDel(data){
      this.$confirm('是否确认删除该公定参数?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await deleteVarietyParameters({
          idList:[data.id]
        });
        if (res.code == 1) {
          this.$message({
            message: '删除成功',
            iconClass: 'el-icon-success',
            customClass: 'common-message'
          });
          this.getTableData(true);
        }
      });
    },
    // 添加公定参数
    addCommonParameter(){
      this.$refs['AddCommonParameter'].show();
    },
    //获取列表
    async getTableData() {
      let form = Object.assign({}, this.search);
      const res = await queryVarietyParameters(form);
      this.loading = false
      if (res.code == 1) {
        this.tableData = res.data.records;
        this.total = res.data.total;
      }
    },
    onSearch(){
      this.search.page = 1
      this.getTableData()
    },
    handleSizeChange(val) {
      this.search.page = 1;
      this.search.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.search.page = val;
      this.getTableData();
    },
    getHeight() {
        this.tableHeight = this.$refs.pageView.offsetHeight - 240;
        console.log(this.tableHeight);
      
    },
  },
};
</script>
<style lang="scss">
@import '~@/assets/css/preplan.scss';
</style>
<style lang="scss">
.common-parameter {
  height: 100%;
  overflow: hidden;
  .select {
    background: #f6f9fc;
    padding: 10px 5px;
  }
  .time:before {
    content: '时间:';
    color: #606d86;
    font-style: normal;
  }
  .el-date-editor {
    .el-input__suffix-inner {
      .el-input__icon:after {
        width: 15px;
        position: relative;
        top: 12px;
        right: 5px;
        background: url('~@/assets/img/time.jpg') no-repeat;
      }
      .el-input__icon.el-icon-circle-close:after {
        display: none;
      }
    }
  }
}
</style>


